/*
 * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Unlicense OR CC0-1.0
 */


#pragma once

#include "esp_blufi_api.h"

#define BLUFI_NET_CONFIG "BLUFI_NET_CONFIG"
#define BLUFI_INFO(fmt, ...)   ESP_LOGI(BLUFI_NET_CONFIG, fmt, ##__VA_ARGS__)
#define BLUFI_ERROR(fmt, ...)  ESP_LOGE(BLUFI_NET_CONFIG, fmt, ##__VA_ARGS__)

#define BLUFI_NET_CONFIG_BIT_STANDBY               BIT0
#define BLUFI_NET_CONFIG_BIT_STARTUP               BIT1
#define BLUFI_NET_CONFIG_BIT_CONFIGING             BIT2
#define BLUFI_NET_CONFIG_BIT_TIMEOUT               BIT3
#define BLUFI_NET_CONFIG_BIT_CLOSE                 BIT4
#define BLUFI_ALL_EVENT_BIIS                      (BIT0 | BIT1 | BIT2 | BIT3 | BIT4)

// wifi事件
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT      BIT1
#define WIFI_ALL_EVENT_BIIS                      (BIT0 | BIT1)

enum en_blufi_step {
    BLUEFI_STEP_STANDBY = 0,
    BLUEFI_STEP_TERMINAL = 1,
    BLUEFI_STEP_WIFI_CONFIG = 2,
    BLUEFI_STEP_WIFI_CONNECTED = 3,
    BLUEFI_STEP_EMQ = 4,
    BLUEFI_STEP_TIMEOUT = 5
};

void blufi_dh_negotiate_data_handler(uint8_t *data, int len, uint8_t **output_data, int *output_len, bool *need_free);
int blufi_aes_encrypt(uint8_t iv8, uint8_t *crypt_data, int crypt_len);
int blufi_aes_decrypt(uint8_t iv8, uint8_t *crypt_data, int crypt_len);
uint16_t blufi_crc_checksum(uint8_t iv8, uint8_t *data, int len);

int blufi_security_init(void);
void blufi_security_deinit(void);
int esp_blufi_gap_register_callback(void);
esp_err_t esp_blufi_host_init(void);
esp_err_t esp_blufi_host_and_cb_init(esp_blufi_callbacks_t *callbacks);
esp_err_t esp_blufi_host_deinit(void);
esp_err_t esp_blufi_controller_init(void);
esp_err_t esp_blufi_controller_deinit(void);

void blufi_net_config_init(void);
void blufi_net_config_close(void);

void blufi_key_init(void);